package com.game.arena.bean;

import com.game.center.AsyncArenaDao;
import com.game.center.respository.ArenaRespository;
import com.game.common.concurrent.GameEventExecutorGroup;
import com.game.gateway.context.ServerConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

@Configuration
public class BeanConfiguration {

    @Autowired
    private ServerConfig serverConfig;//注入配置信息

    private GameEventExecutorGroup dbExecutorGroup;
    @Autowired
    private ArenaRespository arenaRespository; //注入数据库操作类

    @PostConstruct
    public void init() {
        dbExecutorGroup = new GameEventExecutorGroup(serverConfig.getDbThreads());//初始化db操作的线程池组
    }

    @Bean
    public AsyncArenaDao asyncPlayerDao() {//配置AsyncPlayerDao的Bean
        return new AsyncArenaDao(dbExecutorGroup, arenaRespository);
    }
}
